home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Src Code / TEEUPDOW.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  3.1 KB  |  118 lines

  1. {*****************************************}
  2. {   TeeChart-Pro 4.0                      }
  3. {   Copyright (c) 1995-98 David Berneda   }
  4. {                                         }
  5. {    TUpDown component for Delphi 1       }
  6. {*****************************************}
  7. unit TeeUpDow;
  8.  
  9. interface
  10.  
  11. uses
  12.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  13.   Forms, Dialogs, Spin;
  14.  
  15. type
  16.   TUpDown = class(TSpinButton)
  17.   private
  18.     { Private declarations }
  19.     FMin      :Integer;
  20.     FMax      :Integer;
  21.     FPosition :Integer;
  22.     FIncrement:Integer;
  23.     FAssociate:TControl;
  24.     FWrap     :Boolean;
  25.   protected
  26.     { Protected declarations }
  27.     procedure UpClick(Sender: TObject);
  28.     procedure DownClick(Sender: TObject);
  29.     Function GetPosition:Integer;
  30.     Procedure SetPosition(Value:Integer);
  31.     procedure SetAssociate(Value:TControl);
  32.   public
  33.     { Public declarations }
  34.     Constructor Create(AOwner:TComponent); override;
  35.   published
  36.     { Published declarations }
  37.     property Associate:TControl read FAssociate write SetAssociate;
  38.     property Increment:Integer read FIncrement write FIncrement default 1;
  39.     property Max:Integer read FMax write FMax default 100;
  40.     property Min:Integer read FMin write FMin default 0;
  41.     property Position:Integer read GetPosition write SetPosition default 0;
  42.     property Wrap:Boolean read FWrap write FWrap default False;
  43.     property DownGlyph stored False;
  44.     property UpGlyph stored False;
  45.   end;
  46.  
  47. procedure Register;
  48.  
  49. implementation
  50.  
  51. Uses TeeConst,StdCtrls;
  52.  
  53. Constructor TUpDown.Create(AOwner:TComponent);
  54. begin
  55.   inherited Create(AOwner);
  56.   FMin:=0;
  57.   FMax:=100;
  58.   FPosition:=0;
  59.   FIncrement:=1;
  60.   FAssociate:=nil;
  61.   FWrap:=False;
  62.   OnUpClick:=UpClick;
  63.   OnDownClick:=DownClick;
  64. end;
  65.  
  66. procedure TUpDown.SetAssociate(Value:TControl);
  67. begin
  68.   FAssociate:=Value;
  69.   if Assigned(FAssociate) then
  70.      if FAssociate is TCustomEdit then
  71.         (FAssociate as TCustomEdit).Text:=IntToStr(FPosition);
  72. end;
  73.  
  74. Function TUpDown.GetPosition:Integer;
  75. begin
  76.   result:=0;
  77.   if Assigned(FAssociate) then
  78.      if FAssociate is TCustomEdit then
  79.         result:=StrToInt((FAssociate as TCustomEdit).Text);
  80. end;
  81.  
  82. Procedure TUpDown.SetPosition(Value:Integer);
  83. begin
  84.   FPosition:=Value;
  85.   if Assigned(FAssociate) then
  86.      if FAssociate is TCustomEdit then
  87.         (FAssociate as TCustomEdit).Text:=IntToStr(FPosition);
  88. end;
  89.  
  90. procedure TUpDown.UpClick(Sender: TObject);
  91. begin
  92.   Inc(FPosition,FIncrement);
  93.   if FPosition>FMax then
  94.      if FWrap then FPosition:=FMin
  95.               else FPosition:=FMax;
  96.   if Assigned(FAssociate) then
  97.      if FAssociate is TCustomEdit then
  98.         (FAssociate as TCustomEdit).Text:=IntToStr(FPosition);
  99. end;
  100.  
  101. procedure TUpDown.DownClick(Sender: TObject);
  102. begin
  103.   Dec(FPosition,FIncrement);
  104.   if FPosition<FMin then
  105.      if FWrap then FPosition:=FMax
  106.               else FPosition:=FMin;
  107.   if Assigned(FAssociate) then
  108.      if FAssociate is TCustomEdit then
  109.         (FAssociate as TCustomEdit).Text:=IntToStr(FPosition);
  110. end;
  111.  
  112. procedure Register;
  113. begin
  114.   RegisterComponents(TeeMsg_TeeChartPalette, [TUpDown]);
  115. end;
  116.  
  117. end.
  118.